package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Menu;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IMenuService;
import cn.wolfcode.crm.util.JSONResult;
import cn.wolfcode.crm.util.PageResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("menu")
public class MenuController {

    @Autowired
    private IMenuService menuService;

    @RequestMapping("selectEmployeeMenu")
    @ResponseBody
    public List<Menu> selectEmployeeMenu() {
        return menuService.selectEmployeeMenu();
    }

    @RequestMapping("selectRootMenu")
    @ResponseBody
    public List<Menu> selectRootMenu() {
        return menuService.selectRootMenu();
    }

    @RequestMapping("selectByRoleId")
    @ResponseBody
    public List<Menu> selectByRoleId(Long roleId) {
        return menuService.selectByRoleId(roleId);
    }

    @RequestMapping("saveOrUpdate")
    @RequiresPermissions(value = {"menu:saveOrUpdate","菜单新增/更新"},logical = Logical.OR)
    @ResponseBody
    public Object saveOrUpdate(Menu menu) {
        JSONResult result = new JSONResult();
        try {
            menuService.saveOrUpdate(menu);
        } catch (Exception e) {
            result.remark(e.getMessage());
            e.printStackTrace();
        }
        return result;
    }
}
